package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.vo.ItinerarySummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.TravelItinerarySummary;
import com.ktgj.customer.service.ITravelItinerarySummaryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 行程概要Controller
 * 
 * @author ruoyi
 * @date 2022-01-13
 */
@RestController
@RequestMapping("/summary")
public class TravelItinerarySummaryController extends BaseController
{
    @Autowired
    private ITravelItinerarySummaryService travelItinerarySummaryService;

    /**
     * 查询行程概要列表
     */
    @PreAuthorize(hasPermi = "customer:summary:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelItinerarySummary travelItinerarySummary)
    {
        startPage();
        List<TravelItinerarySummary> list = travelItinerarySummaryService.selectTravelItinerarySummaryList(travelItinerarySummary);
        return getDataTable(list);
    }

    /**
     * 导出行程概要列表
     */
    @PreAuthorize(hasPermi = "customer:summary:export")
    @Log(title = "行程概要", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelItinerarySummary travelItinerarySummary) throws IOException
    {
        List<TravelItinerarySummary> list = travelItinerarySummaryService.selectTravelItinerarySummaryList(travelItinerarySummary);
        ExcelUtil<TravelItinerarySummary> util = new ExcelUtil<TravelItinerarySummary>(TravelItinerarySummary.class);
        util.exportExcel(response, list, "行程概要数据");
    }

    /**
     * 获取行程概要详细信息
     */
    @PreAuthorize(hasPermi = "customer:summary:query")
    @GetMapping(value = "/{travelItinerarySummaryId}")
    public AjaxResult getInfo(@PathVariable("travelItinerarySummaryId") Long travelItinerarySummaryId)
    {
        return AjaxResult.success(travelItinerarySummaryService.selectTravelItinerarySummaryById(travelItinerarySummaryId));
    }

    /**
     * 新增行程概要
     */
    @PreAuthorize(hasPermi = "customer:summary:add")
    @Log(title = "行程概要", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelItinerarySummary travelItinerarySummary)
    {
        return toAjax(travelItinerarySummaryService.insertTravelItinerarySummary(travelItinerarySummary));
    }

    /**
     * 修改行程概要
     */
    @PreAuthorize(hasPermi = "customer:summary:edit")
    @Log(title = "行程概要", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelItinerarySummary travelItinerarySummary)
    {
        return toAjax(travelItinerarySummaryService.updateTravelItinerarySummary(travelItinerarySummary));
    }

    /**
     * 删除行程概要
     */
    @PreAuthorize(hasPermi = "customer:summary:remove")
    @Log(title = "行程概要", businessType = BusinessType.DELETE)
	@DeleteMapping("/{travelItinerarySummaryIds}")
    public AjaxResult remove(@PathVariable Long[] travelItinerarySummaryIds)
    {
        return toAjax(travelItinerarySummaryService.deleteTravelItinerarySummaryByIds(travelItinerarySummaryIds));
    }

    /**
     * 查询指定旅游产品的行程概要详细信息
     * */
    @PostMapping("/itinerarySummaryVoList")
    public AjaxResult itinerarySummaryVoList(@RequestBody Map<String, Object> map) {
        if (map.get("groupId") != null && !map.get("groupId").equals("")){
            Long groupId = Long.valueOf(map.get("groupId").toString());
            List<ItinerarySummaryVo> itinerarySummaryVoList;
            try {
                itinerarySummaryVoList = travelItinerarySummaryService.itinerarySummaryVoList(groupId);
            } catch (Exception e){
                return AjaxResult.error(e.getMessage());
            }

            if (itinerarySummaryVoList != null && itinerarySummaryVoList.size() > 0){
                return AjaxResult.success(itinerarySummaryVoList);
            }
            else {
                return AjaxResult.error("未查到数据");
            }
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }
    }
}
